package flc.ast.adapter;

import android.graphics.Color;
import android.view.View;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;

import flc.ast.R;
import flc.ast.databinding.ItemTrlSelLanguageBinding;
import stark.common.basic.adapter.BaseDBRVAdapter;
import stark.common.other.LanCode;

/**
 * @Author: XiaoDan
 * @Date: 2023/12/21
 * @Description:
 */
public class LanguageAdapter extends BaseDBRVAdapter<LanCode, ItemTrlSelLanguageBinding> {
    private LanCode mSelectedLanCode;

    public LanguageAdapter() {
        super(R.layout.item_trl_sel_language, 0);
    }

    @Override
    protected void convert(@NonNull BaseDataBindingHolder<ItemTrlSelLanguageBinding> holder, LanCode item) {
        super.convert(holder, item);
        ItemTrlSelLanguageBinding binding = holder.getDataBinding();
        binding.tvLan.setText(item.getName());
        if (mSelectedLanCode != null && mSelectedLanCode.equals(item)) {
            binding.ivSelFlag.setVisibility(View.VISIBLE);
            binding.tvLan.setTextColor(Color.parseColor("#7B6FEE"));
        } else {
            binding.ivSelFlag.setVisibility(View.INVISIBLE);
            binding.tvLan.setTextColor(Color.parseColor("#313131"));
        }

    }

    public void setSelectedLanCode(LanCode selectedLanCode) {
        if (selectedLanCode != mSelectedLanCode) {
            mSelectedLanCode = selectedLanCode;
            notifyDataSetChanged();
        }
    }

    public LanCode getSelectedLanCode() {
        return mSelectedLanCode;
    }
}
